import router from "./router";
import pinia from "./store";
import useUserStore from "./store/modules/user.ts";
let userStore = useUserStore(pinia);
//@ts-ignore
import NProgress from "nprogress";
//引入进度条的样式
import "nprogress/nprogress.css";
//进度条的加载小圆球不要
NProgress.configure({ showSpinner: false });
//存储用户未登录可以访问路由得路径
let whiteList = [
  "/home",
  "/hospital/register",
  "/hospital/detail",
  "/hospital/notice",
  "/hospital/close",
  "/hospital/search",
];
router.beforeEach((to, from, next) => {
  NProgress.start();
  document.title = `商医通-`+ to.meta.title
  let token = userStore.userInfo.token;
  if (token) {
    next();
  } else {
    //用户未登录
    if (whiteList.includes(to.path)) {
      next();
    } else {
      //登录组件显示不来
      userStore.visiable = true;
    //   next({ path: "/home", query: { redirect: to.fullPath } });
    }
  }
});
//后置路由
router.afterEach((to, from) => {
  //访问路由组件成功,进度条消息
  NProgress.done();
});
